<?php
		
//创建本地文件夹
// 		$addtime=date("Ymd",time());
// 		$filename=time();
// 		defined('LOCAL_PATH');
// 		$testdir=LOCAL_PATH.$addtime."/";
// 		if(file_exists($testdir)):
// 		else:
// 		mkdir($testdir,0777);
// 		endif;
// 		move_uploaded_file($_FILES["Filedata"]["tmp_name"],$testdir.$_FILES["Filedata"]["name"]);




		/**
		 *上传文件到oss服务器 
		 * 加载sdk包以及错误代码包
		 */
		require_once './sdk.class.php';
		
		
		//创建本地文件夹
		$addtime=date("Ymd",time());
		$filename=time();
		defined('LOCAL_PATH');
		$testdir=LOCAL_PATH.$addtime."/";
		if(file_exists($testdir)):
		else:
		mkdir($testdir,0777);
		endif;
		//配置oss上传参数
		$oss_sdk_service = new ALIOSS();
		$oss_sdk_service->set_debug_mode(FALSE);
		$oss_sdk_service->set_enable_domain_style(TRUE);
		defined('OSS_Bucket');
		$bucket = OSS_Bucket;
		
		
		$content = '';
		$length = 0;
		$fp = fopen($_FILES["Filedata"]["tmp_name"],'r');
		if($fp)
		{
			$f = fstat($fp);
			$length = $f['size'];
			while(!feof($fp))
			{
				$content .= fgets($fp,8192);
			}
		}
		$type=substr(strrchr($_FILES["Filedata"]["name"], '.'), 1);
		$fileallname=$filename.'.'.$type;
		$path= $addtime.'/'.$fileallname;
		$upload_file_options = array('content' => $content, 'length' =>$length);
		$oss_sdk_service->upload_file_by_content($bucket,$path,$upload_file_options);
		$img_url = "http://" . $bucket . ".oss-cn-hangzhou.aliyuncs.com/" . $path;

		//保存图片到本地
		$image = file_get_contents($img_url);
		file_put_contents($testdir.$fileallname, $image);
		echo $img_url;
		
?>